﻿using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class UISHWB04:UIWBDAT
    {
        #region ==LOOMID===========
        public static readonly DependencyProperty LOOMIDProperty = DependencyProperty.Register("LOOMID",
            typeof(string), typeof(UISHWB04),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLOOMIDChanged));
        public string LOOMID
        {
            get
            {
                return (string)GetValue(LOOMIDProperty);
            }
            set
            {
                SetValue(LOOMIDProperty, value);
                OnLOOMIDChg();
            }
        }
        private static void OnLOOMIDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UISHWB04;
            if (src != null)
            {
                src.LOOMID = (string)e.NewValue;
            }
        }
        public virtual void OnLOOMIDChg()
        { }
        #endregion 
        public UISHWB04()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWBDAT();
            this.DataContext = MV;
            
        }

        public override void OnEXAUFChg(string vlaue)
        {
            STKNR = "";
            TBMain.Clear();
            if (EXAUF.Length < 12)
                return;
            dwData = TBMain.NewRow();
            dwData["WBMANDANT"] = app.Mandant;
            dwData["WBBESTKZ"] = EXAUF.Substring(0, 1);
            dwData["WBBESTKRS"] = EXAUF.Substring(1, 2);
            dwData["WBBESTLFD"] = EXAUF.Substring(3, 6);
            dwData["WBBESTPOS"] = EXAUF.Substring(9, 3);
            SResult = TMV.QWBDAT02(dwData);
            MergeData(SResult, true);
            base.OnEXAUFChg(vlaue);
        }
        public override void LOADBYAUF()
        {
            TBMain.Clear();
            if (ORDERNUM.Length < 8)
            {
                return;
            }
            dwData = TBMain.NewRow();
            dwData["WBMANDANT"] = app.Mandant;
            dwData["WBRWKRS"] = ORDERNUM.Substring(0, 2);
            dwData["WBRWLFD"] = ORDERNUM.Substring(2, 6);
            SResult = TMV.QWBDAT01(dwData);
            MergeData(SResult, true);
            base.LOADBYAUF();
        }
        public override void NewCommand(object sender, RoutedEventArgs e)
        {
            PM["ROLLS"] = ROLLS;
            PM["RLG"] = RLG;
            PM["IsAppend"] = IsAppend;
            PM["dwABP"] = dwABP;
            PM["ACTRLFD"] = ACTRLFD;
            PM["WB04KEY"] = KEY;
            PM["CUSER"] = app.User;
            PM["PARTIE"] = PARTIE;
            PM["IsClear"] = true;
            PM["VKDELDATE"] = VKDELDATE;
            DataTable tb= TMV.NEWWB(PM);
            vwMaster.View.MoveCurrentTo(-1);
            vwMaster.View.MoveCurrentToFirst();
            /*foreach (DataRow rw in tb.Rows)
            {
                string key = rw["WBBRWKRS"].ToString() + rw["WBBRWLFD"].ToString(); 
                KEY = "";
                KEY = key;
                break;
            } */
            base.NewCommand(sender, e);
        }
       
        public override void OnWHChg(string value)
        {

            if (MV == null)
                return;
            if (WH.Length < 4)
                return;
            LO = WH.Substring(0, 2);
            LB = WH.Substring(2, 2);
            LP = WH.Substring(4);
            base.OnWHChg(value);
        }
        public void RLG_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            ROLLS = 0;
        }
    }
}
